import React from 'react';
import {StyleSheet, View, Text, TouchableOpacity, Image} from 'react-native';
import BaseItem from './BaseItem';

export default function PopularItem({item, changeFavorite, onClickItem}) {
  const baseRef = React.useRef();

  return (
    <TouchableOpacity onPress={() => onClickItem(item)}>
      <View style={styles.cellContainer}>
        <Text style={styles.title}>{item.full_name}</Text>
        <Text style={styles.description}>{item.description}</Text>
        <View style={styles.row}>
          <View style={{flexDirection: 'row', alignItems: 'center'}}>
            <Text style={styles.author}>Author:</Text>
            <Image style={styles.img} source={{uri: item.owner.avatar_url}} />
          </View>
          <View
            style={{
              flexDirection: 'row',
              justifyContent: 'space-between',
            }}>
            <Text>Star:</Text>
            <Text>{item.stargazers_count}</Text>
          </View>
          <BaseItem ref={baseRef} item={item} changeFavorite={changeFavorite} />
        </View>
      </View>
    </TouchableOpacity>
  );
}

const styles = StyleSheet.create({
  cellContainer: {
    backgroundColor: '#ffffff',
    padding: 10,
    marginRight: 5,
    marginLeft: 5,
    marginVertical: 3,
    borderColor: '#dddddd',
    borderWidth: 0.5,
    borderRadius: 2,
    shadowColor: '#cccccc',
    shadowOffset: {width: 0.5, height: 0.5},
    shadowOpacity: 0.4,
    shadowRadius: 1,
    elevation: 2, //这是android中设置阴影的
  },
  title: {
    fontSize: 16,
    marginBottom: 2,
    color: '#212121',
  },
  author: {
    marginRight: 6,
  },
  img: {
    height: 22,
    width: 22,
  },
  description: {
    fontSize: 14,
    marginBottom: 2,
    color: '#757575',
  },
  row: {
    justifyContent: 'space-between',
    flexDirection: 'row',
    alignItems: 'center',
  },
});
